package com.example.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.example.cloud.apis.PayFeignApi;
import com.example.cloud.entities.PayDTO;
import com.example.cloud.resp.ResultData;
import com.example.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Yun
 * @Date: 2024/3/18
 */
@RestController
@RequestMapping("/feign/pay")
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping("/insert")
    public ResultData insertOrder(@RequestBody PayDTO payDTO) {
        ResultData resultData = payFeignApi.insertPay(payDTO);
        return resultData;
    }

    @GetMapping("/select/{id}")
    public ResultData selectPayById(@PathVariable("id") Integer id) {
        ResultData resultData = null;
        try {
            System.out.println("调用开始:" + DateUtil.now());
            resultData = payFeignApi.selectPayById(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("调用结束:" + DateUtil.now());
            ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        return resultData;
    }

    @GetMapping("/mylb")
    public String mylb() {
        return payFeignApi.mylb();
    }
}

